#include <iostream>
#include <queue>
#include <semaphore.h>
using namespace std;

class BoundedBlockingQueue {
private:
    queue<int>q;
    int capacity;
    mutex M;
    condition_variable cv_data;

public:
    BoundedBlockingQueue(int capacity): capacity(capacity) {
        
    }
    
    void enqueue(int element) {
        unique_lock<mutex> locks(M);
        cv_data.wait(locks,[this]{return q.size()<capacity;});
        q.push(element);
        cv_data.notify_all();
    }
    
    int dequeue() {
        int t;
        unique_lock<mutex> locks(M);
        cv_data.wait(locks,[this]{return q.size()>0;});
        t=q.front();
        q.pop();
        cv_data.notify_all();
        return t;
    }
    
    int size() {
        return q.size();
    }
};